[文章作者:张宴 本文版本:v1.0 最后修改:2008.11.20 转载请注明原文链接:http://blog.s135.com/post/380.htm]

  Linux下限制网卡的带宽,可用来模拟服务器带宽耗尽,从而测试服务器在此时的访问效果。

  1、安装iproute
yum -y install iproute


  2、限制eth0网卡的带宽为50kbit:
/sbin/tc qdisc add dev eth0 root tbf rate 50kbit latency 50ms burst 1000


  3、限制带宽为50kbit后,在百兆局域网中wget下载一个大文件:
[root@localhost ~]# wget http://192.168.1.7/test.zip
--19:40:27--  http://192.168.1.7/test.zip
Connecting to 192.168.1.7:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23862312 (23M) [application/zip]
Saving to: `test.zip'

37% [=======>   ] 8,994,816    457K/s  eta 27s

  下载速度为457K/s,限制效果达到。

  4、解除eth0网卡的带宽限制:
/sbin/tc qdisc del dev eth0 root tbf


  5、对比:未作带宽限制情况下,在百兆局域网中wget下载一个大文件:
[root@localhost ~]# wget http://192.168.1.7/test.zip    
--19:44:33--  http://192.168.1.7/test.zip
Connecting to 192.168.1.7:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23862312 (23M) [application/zip]
Saving to: `test.zip'

100%[==========>] 23,862,312  6.14M/s   in 3.7s  

19:44:36 (6.16 MB/s) - `test.zip' saved [23862312/23862312]

  下载速度为6.16MB/s。

Tags: , ,
技术大类 » 其他Unix技术 | 评论(4) | 引用(0) | 阅读(1519)
gengmao
2008-11-20 18:25
限制带宽为50kbit后, 为什么下载速度达到457K/s?
张宴 回复于 2008-11-20 18:35
Linux内核依靠粗糙的计时信息进行带宽固定。在一个较长的时间段内,可以维持很好的精度,但是在以秒为单位进行计量的时间段内,其结果非常不准确。
所以,实际使用的带宽需要以wget下载时速度为准,去调整tc的带宽限制。
tengcy Email Homepage
2008-11-20 19:08
单位搞错了,应该是50Mbit。。。
jacket Homepage
2008-11-22 03:35
做下载站可以用这个方法了

这个方法很耗CPU吗?
xi2008wang Email
2008-11-23 16:44
前几天,正好用了windows下面的网络带宽限制软件. 也是用于模拟外网
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]